export const $$ = Dom7;

export const app = new Framework7({
    id: 'valkyrja',
    name: '提示',
    el: '#app',
    theme: 'auto',
    version: '1.0',
    dialog: {
        buttonOk: '确定',
        buttonCancel: '取消',
    },
    popup: {
        closeByBackdropClick: false,
        animate: false
    },
    view: {
        browserHistory: true,
        browserHistorySeparator: '#',
        browserHistoryOnLoad: false
    },
    toast: {
        closeButtonText: '关闭',
        closeTimeout: 3000,
        horizontalPosition: 'center',
        position: 'top',
        closeButton: true
    }
})

export function _toast(msg) {
    app.toast.create({ text: msg }).open();
}

// 防止连续点击
const _timer = {}
export function _delay(id, fn, wait=300) {
    if (_timer[id]) {
        clearTimeout(_timer[id]);
        delete _timer[id];
    }

    return _timer[id] = setTimeout(() => {
        fn();
        delete _timer[id];
    }, wait);
}

const _timeouter = {}
export function _timeout(id, fn, wait=300) {
    return _timeouter[id] = setTimeout(() => {
        fn();
        clearTimeout(_timeouter[id]);
        delete _timeouter[id];
    }, wait);
}

export function _sleep(time) {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve();
        }, time);
    });
}